<template>
  <div class="app-container">
    <div class="search-container">
      <el-form ref="queryFormRef" :model="queryParams" label-width="auto" :inline="true">
        <el-form-item label="渠道" prop="channelIds">
          <el-select multiple clearable @keyup.enter="handleQuery" v-model="queryParams.channelIds" placeholder="请选择" style="width: 256px">
            <el-option v-for="item in channelArr" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="类型" prop="type">
          <el-select clearable @keyup.enter="handleQuery" v-model="queryParams.type" placeholder="请选择" style="width: 256px">
            <el-option :value="1" label="客服事件" />
            <el-option :value="2" label="判罚事件" />
          </el-select>
        </el-form-item>
        <el-form-item label="类型" prop="status">
          <el-select clearable @keyup.enter="handleQuery" v-model="queryParams.status" placeholder="请选择" style="width: 256px">
            <el-option :value="0" label="待处理" />
            <el-option :value="1" label="已回复" />
            <el-option :value="2" label="已完成" />
          </el-select>
        </el-form-item>
        <el-form-item prop="orderId" label="订单号">
          <el-input placeholder="请输入" v-model="queryParams.orderId" @keyup.enter="handleQuery"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="handleQuery">
            <template #icon><Search /></template>
            搜索
          </el-button>
          <el-button @click="handleResetQuery">
            <template #icon><Refresh /></template>
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never" class="table-container">
      <el-table v-loading="loading" :data="TableData" highlight-current-row row-key="id" @row-click="handleRowClick">
        <el-table-column min-width="100" label="订单号" align="center" prop="orderId"></el-table-column>
        <el-table-column min-width="100" label="事件类型" align="center">
          <template #default="scope">
            <div v-if="scope.row.type == 1">客服事件</div>
            <div v-else-if="scope.row.type == 2">判罚事件</div>
          </template>
        </el-table-column>
        <el-table-column min-width="100" label="状态" align="center" prop="status">
          <template #default="scope">
            <div v-if="scope.row.status == 0">待处理</div>
            <div v-else-if="scope.row.status == 1">已回复</div>
            <div v-else-if="scope.row.status == 2">已完成</div>
          </template>
        </el-table-column>
        <el-table-column min-width="100" label="平台" align="center" prop="platFormEnum">
          <template #default="scope">
            <div>{{ platFormEnum[scope.row.platformId] }}</div>
          </template>
        </el-table-column>
        <el-table-column min-width="140" label="渠道" align="center" prop="channelId">
          <template #default="scope">
            <div>{{ channelEnum[scope.row.channelId] }}</div>
          </template>
        </el-table-column>
        <el-table-column min-width="140" label="渠道状态" align="center" prop="channelStatus">
          <template #default="scope">
            <div v-if="scope.row.channelStatus == 0">待处理</div>
            <div v-else-if="scope.row.channelStatus == 1">通过</div>
            <div v-else-if="scope.row.channelStatus == 2">拒绝</div>
          </template>
        </el-table-column>
        <el-table-column min-width="200" label="内容" align="center" prop="content"></el-table-column>
        <el-table-column min-width="100" label="创建时间" align="center" prop="createTime"></el-table-column>
        <el-table-column fixed="right" align="center" label="操作" width="220">
          <template #default="scope">
            <div style="display: flex; justify-content: center; align-items: center">
              <el-button type="danger" link size="small" @click.stop="handleAppeal(scope.row)">
                <template #icon><RemoveFilled /></template>
                申诉
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-if="total > 0" v-model:total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize" @pagination="handleQuery" />
    </el-card>
    <!-- 改派 -->
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: "SysMenu",
  inheritAttrs: false,
});

import OrderApi from "@/api/order";
import CommonApi from "@/api/common";
import sendModal from "./components/sendModal.vue";
import logModal from "./components/logModal.vue";
import actionModal from "./components/actionModal.vue";
import moneyModal from "./components/moneyModal.vue";
import { orderStatusEnum, platFormEnum, channelEnum, orderTypeEnum, bizTypeEnum, luggageEnum, channelArr, bizTypeArr, orderTypeArr, platFormArr, carTypeArr } from "@/enums/common";
import { MenuTypeEnum } from "@/enums/MenuTypeEnum";
import router from "@/router";

const queryFormRef = ref(ElForm);
const total = ref(0);

const loading = ref(false);

// 查询参数
const queryParams = reactive<MenuQuery>({
  pageNo: 1,
  pageSize: 10,
});
// 菜单表格数据
const TableData = ref([]);

// 选择表格的行菜单ID
const selectedMenuId = ref<number | undefined>();

//申诉
function handleAppeal(row) {
  // router.push(`/priceRuleInfo?data=${JSON.stringify(data)}`);
  router.push(`/appeal?id=${row.id}`);
}
// 查询菜单
function handleQuery() {
  loading.value = true;
  OrderApi.eventList(queryParams)
    .then((data) => {
      TableData.value = data.result;
      total.value = data.total * 1;
    })
    .finally(() => {
      loading.value = false;
    });
}

// 重置查询
function handleResetQuery() {
  queryFormRef.value.resetFields();
  queryParams.pageNo = 1;
  handleQuery();
}

// 行点击事件
function handleRowClick(row: MenuVO) {
  // 记录表格选择的菜单ID，新增子菜单作为父菜单ID
  selectedMenuId.value = row.id;
}

onMounted(() => {
  handleQuery();
});
</script>
<style lang="scss" scoped>
.red_rate {
  color: red;
}
.address_box {
  display: flex;
  flex-direction: column;
  align-items: left;
  justify-content: left;
  .item {
    display: flex;
    align-items: center;
    margin: 4px 0;
    .tag {
      width: 50px;
      height: 23px;
      text-align: center;
      color: orange;
      background: #fff8e6;
    }
    .tag2 {
      color: #3fd175;
      background: #e7faf0;
    }
  }
}
</style>
